function Promiseall(iterators){
    const promises=Array.from(iterators);
    const len=promises.length;
    const resultList=[];
    let count=0;
    return new Promise((resolve,reject)=>{
        for(let i in promises){
            promises[i]
            .then((res)=>{
                resultList[i]=res;
                count++;
                if(count===len){
                    resolve(resultList);
                }
            })
            .catch((err)=>{
                reject(err);
            })
        }
    })
}

const promise1 = Promise.resolve('promise1');
const promise2 = new Promise(function (resolve, reject) {
    setTimeout(resolve, 2000, 'promise2');
});
const promise3 = new Promise(function (resolve, reject) {
    setTimeout(resolve, 1000, 'promise3');
});
const promise4=new Promise((resolve,reject)=>reject('NO'))

Promiseall([promise1, promise2, promise3]).then(function(values) {
    console.log(values);
}).catch((reason)=>console.log(reason))
